package jianzhi_offer;

import java.util.ArrayList;

public class _2_从尾到头打印链表 {
	public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
		ArrayList<Integer> res = new ArrayList<Integer>();
		ListNode fake = new ListNode(0);
		ListNode now;
		while(listNode != null) {//头插法
			now = listNode;
			listNode = listNode.next;
			now.next = fake.next;
			fake.next = now;
		}
		now = fake.next;
		while(now != null) {
			res.add(now.val);
			now = now.next;
		}
		return res;
    }
}
